package com.zlq.javaWeb3.filter;

import com.zlq.javaWeb3.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(urlPatterns = "/loginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        resp.setCharacterEncoding("UTF-8");

        String name = req.getParameter("name");
        String password = req.getParameter("password");
        if ("pxy".equals(name) && "123".equals(password)){
            req.getSession().setAttribute("name",name);
            System.out.println("登录成功");
            resp.sendRedirect("company.jsp");
        }else {

            req.getRequestDispatcher("oop.jsp").forward(req,resp);
        }
//        User user = new User(name,password);
//        resp.sendRedirect("oop.jsp");
    }
}
